@echo off
title Ruoyi-ai Application Status Script

set APP_NAME=ruoyi-admin
set APP_HOME=%~dp0
set PID_FILE=%APP_HOME%app.pid

echo Checking status of %APP_NAME%...

REM 检查PID文件是否存在
if not exist "%PID_FILE%" (
  echo Application is not running (PID file not found).
  pause
  exit /b 1
)

REM 读取PID
set /p PID=<"%PID_FILE%"

REM 检查进程是否存在
tasklist /FI "PID eq %PID%" /FO CSV | findstr /I "%PID%" >nul

if %errorlevel% equ 0 (
  echo %APP_NAME% is running. PID: %PID%
  
  REM 显示进程详细信息
  tasklist /FI "PID eq %PID%"
) else (
  echo Application is not running (process with PID %PID% not found).
  echo Removing stale PID file...
  del /f /q "%PID_FILE%" >nul 2>&1
  pause
  exit /b 1
)

pause